#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
#define int long long
signed main() {
	int n;
	cin >> n;
	vector<pii> a(n);

	for (int i = 1; i <= n; i++)
		cin >> a[i - 1].first >> a[i - 1].second;

	sort(a.begin(), a.end(), [](pii x, pii y) {
		if (x.second != y.second)
			return x.second < y.second;
		else
			return x.first < y.first;
	});

	int ans = 1, pre = a[0].second;
	for (int i = 1; i < n; i++) {
		if (a[i].first >= pre) {
			ans++;
			pre = a[i].second;
		}
	}
	cout << ans;
	return 0;
}
